#include "AwesomeAttraction.h"
#include <windows.h>
#include <GL/gl.h>

CAwesomeAttraction::CAwesomeAttraction(void):m_size(1), m_rotationPillar(this, 0), m_rotationArm(this, 0), m_rotationBooth(this, 0){}

void CAwesomeAttraction::doRender()
{
	//pillar
	glPushMatrix();
		glScalef(m_size, m_size, m_size);
		glRotatef(m_rotationPillar, 0, 1, 0);
		drawCube(2);
		glTranslatef(0, 2, 0);
		drawCube(2);
		glTranslatef(0, 2, 0);
		drawCube(2);
		glTranslatef(0, 2, 0);
		drawCube(2);
		glTranslatef(0, 2, 0);
		drawCube(2);
		glTranslatef(0, 2, 0);
		drawCube(2);
		glTranslatef(0, 2, 0);
		drawCube(2);
		glTranslatef(0, 0, 2);
		drawCube(2);
		glTranslatef(0, 0, 2);
		drawCube(2);
		
		//arm
		glPushMatrix();
			glRotatef(m_rotationArm, 0,0, 1);
			glTranslatef(0, 0, 2);
			drawCube(2);
			glTranslatef(2, 0, 0);
			drawCube(2);
			glTranslatef(2, 0, 0);
			drawCube(2);
			glTranslatef(2, 0, 0);
			drawCube(2);
			glTranslatef(2, 0, 0);
			drawCube(2);
			glTranslatef(2, 0, 0);
			glTranslatef(-12, 0, 0);
			drawCube(2);
			glTranslatef(-2, 0, 0);
			drawCube(2);
			glTranslatef(-2, 0, 0);
			drawCube(2);
			glTranslatef(-2, 0, 0);
			drawCube(2);

			//booth
			glPushMatrix();
				glRotatef(m_rotationBooth, 1, 0, 0);
				glTranslatef(-2, 0, 0);
				drawBooth();
			glPopMatrix();
			glPushMatrix();
				glRotatef(-m_rotationBooth, 1, 0, 0);
				glTranslatef(18, 0, 0);
				drawBooth();
			glPopMatrix();

		glPopMatrix();
	glPopMatrix();


	
}

void CAwesomeAttraction::drawCube(float size)
{
	glPushMatrix();
	glTranslatef(-size/2, -size/2, -size/2);
	glBegin(GL_QUADS);
		
		glNormal3f(0, 0, -1);
		glVertex3f(0, 0, 0);
		glVertex3f(size, 0, 0);
		glVertex3f(size, size, 0);
		glVertex3f(0, size, 0);
		
		//ok
		glNormal3f(1, 0, 0);
		glVertex3f(size, size, 0);
		glVertex3f(size, 0, 0);
		glVertex3f(size, 0, size);
		glVertex3f(size, size, size);
		
		//ok
		glNormal3f(-1, 0, 0);
		glVertex3f(0, 0, 0);
		glVertex3f(0, size, 0);
		glVertex3f(0, size, size);
		glVertex3f(0, 0, size);
		
		glNormal3f(0, 0, 1);
		glVertex3f(0, size, size);
		glVertex3f(0, 0, size);
		glVertex3f(size, 0, size);
		glVertex3f(size, size, size);
		
		//ok
		glNormal3f(0, 1, 0);
		glVertex3f(0, size, size);
		glVertex3f(size, size, size);
		glVertex3f(size, size, 0);
		glVertex3f(0, size, 0);

		//ok
		glNormal3f(0, -1, 0);
		glVertex3f(0, 0, 0);
		glVertex3f(size, 0, 0);
		glVertex3f(size, 0, size);
		glVertex3f(0, 0, size);
			
	glEnd();
	glPopMatrix();
}

void CAwesomeAttraction::drawBooth()
{
	glPushMatrix();
		glTranslatef(0, 2, 2);
		glPushMatrix();
			glRotatef(-m_rotationBooth, 1, 0, 0);
			drawCube(1);
		glPopMatrix();
		glTranslatef(0, -2, 0);
		glPushMatrix();
			glRotatef(m_rotationBooth, 1, 0, 0);
			drawCube(1);
		glPopMatrix();
		glTranslatef(0, -2, 0);
		glPushMatrix();
			glRotatef(-m_rotationBooth, 1, 0, 0);
			drawCube(1);
		glPopMatrix();
		glTranslatef(0, 0, -2);
		glPushMatrix();
			glRotatef(m_rotationBooth, 1, 0, 0);
			drawCube(1);
		glPopMatrix();
		glTranslatef(0, 0, -2);
		glPushMatrix();
			glRotatef(-m_rotationBooth, 1, 0, 0);
			drawCube(1);
		glPopMatrix();
		glTranslatef(0, 2, 0); 
		glPushMatrix();
			glRotatef(m_rotationBooth, 1, 0, 0);
			drawCube(1);
		glPopMatrix();
		glTranslatef(0, 2, 0);
		glPushMatrix();
			glRotatef(-m_rotationBooth, 1, 0, 0);
			drawCube(1);
		glPopMatrix();
		glTranslatef(0, 0, 2);
		glPushMatrix();
			glRotatef(m_rotationBooth, 1, 0, 0);
			drawCube(1);
		glPopMatrix();
	glPopMatrix();
}
